<?php
/*
Cogumelo v0.1 - Innoto
Copyright (C) 2009 Innoto Gestión para el Desarrollo Social S.L. <mapinfo@innoto.es>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
USA.
*/

require_once("Classes/Model/Facade/ResourceclassFacade.inc");
require_once("Classes/Model/VO/ResourceclassVO.inc");
require_once("Classes/Controllers/Data/DataController.inc");

//
//
// Resourceclass Controller Class
//
//make
class  ResourceclassController extends DataController
{
	private $data;
	
	//
	//	class constructor, creates ResourceclassFacade object
	//
	function __construct()
	{	
		parent::__construct();
		$this->data = new ResourceclassFacade();
	}
	

	////////////////////////////////////////////
	////////// Find And List Methods //////////
	//////////////////////////////////////////
	
	//
	//	Find by ID
	//
	function Find($id) 
	{
		$data = $this->data->Find($id);
		if($data) $this->logcontrol->addLogLine("Resourceclass with ID=".$id." FOUND", 3);
		else $this->logcontrol->addLogLine("Resourceclass with ID=".$id." NOT FOUND", 3);
		
		return $data;
	}
	

	////////////////////////////////////////////
	/////////////  Input Methods //////////////
	//////////////////////////////////////////
	
	//
	//	Create new Resourceclass (from a hash of data)
	//
	function Create($resourceclass)		
	{  		
		$newresourceclass = new ResourceclassVO(
							null,
							$resourceclass['resourceclass_set'],
							$resourceclass['resourceclass_icon'],
							$resourceclass['resourceclass_tinyicon'],
							$resourceclass['resourceclass_parent'],
							$resourceclass['resourceclass_name_es'],
							$resourceclass['resourceclass_name_gl'],
							$resourceclass['resourceclass_name_en'],
							$resourceclass['resourceclass_text']
						);	

						
		$data = $this->data->Create($newresourceclass);
		
		
		if($data) $this->logcontrol->addLogLine("Resourceclass created with ID=".$data, 3);
		else $this->logcontrol->addLogLine("Unable to create Resourceclass", 3);
		
		return $data;
		
	}

    //
	//	Update resourceclass data from a hash of data 
	function Update($resourceclass)		
	{		
		$newresourceclass = new ResourceclassVO(
							$resourceclass['resourceclass_id'],
							$resourceclass['resourceclass_set'],
							$resourceclass['resourceclass_icon'],
							$resourceclass['resourceclass_tinyicon'],
							$resourceclass['resourceclass_parent'],
							$resourceclass['resourceclass_name_es'],
							$resourceclass['resourceclass_name_gl'],
							$resourceclass['resourceclass_name_en'],
							$resourceclass['resourceclass_text']
							);
							
		$data = $this->data->Update($newresourceclass);
		if($data) $this->logcontrol->addLogLine("resourceclass updated with ID=".$data, 3);
		else $this->logcontrol->addLogLine("Unable to update resourceclass", 3);
		
		return $data;
		
	}

	//
	//	Destroy resourceclass
	//
	function Destroy($id)
	{
		$data = $this->data->Destroy($id);
		if($data) $this->logcontrol->addLogLine("Resourceclass with ID=".$id." destroyed", 3);
		else $this->logcontrol->addLogLine("Unable to remove Resourceclass with ID=".$id, 3);
		
		return $data;
		
	}
	
	
	//
	// List  Resourceclasseses
	//
	function ListResourceclasses($RANGE=null, $ORDER=null)
	{
		$data = $this->data->ListResourceclass($RANGE, $ORDER);
		if($data) $this->logcontrol->addLogLine("Resourceclasses list Generated", 3);
		else $this->logcontrol->addLogLine("EMPTY Resourceclasses list Generated", 3);
		
		return $data;
	}
	//
	// Count Resourceclasseses (Rows number)
	function ListResourceclassesCount()
		{
		$data = $this->data->ListResourceclassCount();
		
		$this->logcontrol->addLogLine("Counted ".$data." Resourceclasses", 3);
				
		return $data;
	    }
	
	
	
}
